package com.EpidemicPrevention.service;

import com.EpidemicPrevention.mapper.RegisterMapper;
import com.EpidemicPrevention.pojo.Register;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegisterServiceImpl implements  RegisterService {
    @Autowired
    private RegisterMapper registerMapper;

    @Override

    public JSON saveRegister ( Register register) {
        JSONObject json = new JSONObject();
        int code = 0;
        code = registerMapper.saveRegister(register);
        if (code ==1){
            json.put("code",1);
            json.put("msg","保存成功");
        }else {
            json.put("code",0);
            json.put("msg","保存失败");
        }
        return json;
    }

    @Override
    public JSON updateRegister(Register register) {
        JSONObject json = new JSONObject();
        try {
            int code=0;
            code=registerMapper.updateRegister(register);
            if (code==1){
                json.put("msg","修改成功");
                json.put("code",1);
            }else{
                json.put("msg","修改失败");
                json.put("code",0);
            }
        }catch (Exception e){
            e.printStackTrace();
            json.put("msg","数据接口异常,请稍后再试");
            json.put("code",-1);
        }
        return json;
    }

    @Override
    public JSON deleteRegister(int r_id) {
        JSONObject json = new JSONObject();
        int code =0;
        code = registerMapper.deleteRegister(r_id);
        if (code ==1){
            json.put("msg","删除成功");
            json.put("code",1);
        }else {
            json.put("msg","删除失败");
            json.put("code",0);
        }
        return json;
    }

    @Override
    public  List<Register> queryRegister (int page, int limit, String r_audit, String Keyword) {
        return registerMapper.queryRegister(page, limit, r_audit, null);
    }

}
